/**
 * @author liangxi
 * @since 2024/4/11
 */

#include "WinnerState.h"
#include "../GumballMachine.h"

void WinnerState::turnCrank() {
    std::cout << "Turning twice does not get you another gumball!\n";
}

void WinnerState::ejectQuarter() {
    std::cout << "Sorry,you already turned the crank\n";
}

void WinnerState::insertQuarter() {
    std::cout << "Please wait,we are already giving you a gumball\n";
}

void WinnerState::dispense() {
    std::cout << "YOU ARE A WINNER! You get two gumballs for your quarter\n";
    mGumballMachine->releaseBall();
    if (mGumballMachine->getMCount() == 0) {
        mGumballMachine->setState(mGumballMachine->getSoldOutState());
    } else {
        mGumballMachine->releaseBall();
        if (mGumballMachine->getMCount() > 0) {
            mGumballMachine->setState(mGumballMachine->getNoQuarterState());
        } else {
            std::cout << "Oops,out of gumballs!\n";
            mGumballMachine->setState(mGumballMachine->getSoldOutState());
        }
    }
}

GumballMachine *WinnerState::getMGumballMachine() const {
    return mGumballMachine;
}

void WinnerState::setMGumballMachine(GumballMachine *gumballMachine) {
    WinnerState::mGumballMachine = gumballMachine;
}
